Nested Routines

The only remaining preventer of all routines showing up in the popup are Pascals lovely "nested functions" thingy.  These are fairly easy to fix.  Sometimes they can be quite complex.

In the Function Pop Up, one of these will be the bottom routine on the list.  They are identified by a start brace but then a complete routine after the variables are declared.  Here’s an example from “Icosahedron”:

In the Pascal to C output, it’s:

// The primary routine beginning.
void Shadefaces()
                        // You have to add this brace.
    short ThisFace;      // These variables...
    RgnHandle aRegion;   // ...do not appear...
    short Level;         // ...in the nested routine.

    // Nested routine begins here.
    double Bright (Coordinates PlaneNorm, Coordinates LightNorm)
    
        Bright = ((PlaneNorm[1] * LightNorm[1] +
                   PlaneNorm[2] * LightNorm[2] + 
                   PlaneNorm[3] * LightNorm[3]) + 1.0) / 2.0
        // End of nested routine.

    // Begin of primary routine.
    aRegion = NewRgn();  // First used from primary variables.
    for (ThisFace = 0; ThisFace < kNumFaces; ThisFace++)

[snip]

level = ceil(Bright(Normal, light) * 64.0);

[snip]
    
    //• Shadefaces.    // End of primary routine.

Select the part above the complete routine and copy it.  In CMaster, hit your hot-keys (or tool icon) to comment this out.

// void Shadefaces()
// 
//     short ThisFace;      // These variables...
//     RgnHandle aRegion;   // ...do not appear...
//     short Level;         // ...in the nested routine.

Now, scroll down until you find the actual start of that copied routine declaration with variables.  There'll be a start brace right after an end brace.  Depending on how many functions are nested within it, the first one of these you find may or may not be where that goes.  Sometimes the author of the Pascal code marks it with a comment (hopefully).  Anyway, wherever you find it, select the start brace, hit RETURN and then paste the declaration and variables.

In our example, here’s what you end up with:

// UN-Nested routine begins here.
double Bright (Coordinates PlaneNorm, Coordinates LightNorm)

    Bright = ((PlaneNorm[1] * LightNorm[1] +
               PlaneNorm[2] * LightNorm[2] + 
               PlaneNorm[3] * LightNorm[3]) + 1.0) / 2.0
    // End of nested routine.

// The primary routine beginning.
void Shadefaces()
                        // You have to add this brace.
    short ThisFace;      // These...
    RgnHandle aRegion;   // ...do not appear...
    short Level;         // ...in the nested routine.
                         // Where original “begin” was.
    aRegion = NewRgn();  // First used from primary variables.
    for (ThisFace = 0; ThisFace < kNumFaces; ThisFace++)

[snip]

level = ceil(Bright(Normal, light) * 64.0);

[snip]
    
    //• Shadefaces.    // End of primary routine.

One way you can find them is to look in the variables in the “primary header declaration” (which you copied and commented out) and find the first occurrence of its use, following it.  There will often be one that is unique to the body of the routine where that declaration goes.  In the example, Bright did not contain ThisFace, aRegion or Level, so you can find the “nest” with those as search strings.  The next occurrence of one of these variables beyond its original location, where there’s a ‘’ followed by a ‘‘ just above it, will be where the primary function beginning goes.

If there are several nested routines, the first set of variables may belong to more than one of them.  You don’t need to be concerned about those until compile time.  A decision will have to be made whether to make several locals or all of those global, at that time.

Now check the Function Pop Up.

So, you just repeat these steps until ALL routines show in the popup.  The last routine - main () - will not be declared.  You’ll have to type in the declaration yourself.  Pascal programmers usually mark this well.

The last brace of the program file (end of “main”) has a dot after it which you may as well remove while you’re there.